<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>01 事件驱动</title>
</head>
<body>
    <div>
        <div>商品数量<input type="text" class="goodnum"></div>
        <div>商品价格<input type="text" class="goodprice"></div>
        <div>小计<span class="total"></span></div>
    </div>
    
</body>

<script>

    let goodnumInput = document.getElementsByClassName("goodnum")[0];
    let goodpriceInput  = document.getElementsByClassName("goodprice")[0];
    let total = document.getElementsByClassName("total")[0];




    goodnumInput.oninput = function(){

        total.innerText = String(goodnumInput.value*goodpriceInput.value);
    }

    goodpriceInput.oninput = function(){
        total.innerText = goodnumInput.value*goodpriceInput.value;
    }



</script>
</html>